package org.wmq.housewebadmin.controller;

import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;
import org.wmq.housemodel.entity.PaymentType;
import org.wmq.housemodel.entity.Result;
import org.wmq.housewebadmin.service.PaymentTypeService;

import java.util.List;

@RestController
@RequestMapping("/admin/payment")
@RequiredArgsConstructor
public class PaymentTypeController {
    private final PaymentTypeService paymentTypeService;

    @GetMapping("/list")
    public Result<List<PaymentType>> listPaymentType(){
        return Result.ok(this.paymentTypeService.getPaymentTypeList());
    }

    @PostMapping("/saveOrUpdate")
    public Result<Void> saveOrUpdatePaymentType(@RequestBody PaymentType paymentType){
        return this.paymentTypeService.saveOrUpdatePaymentType(paymentType);
    }

    @Delete("/{id}")
    public Result<Void> deletePaymentTypeById(@PathVariable Long id){
        boolean success = this.paymentTypeService.deletePaymentTypeById(id);
        if (success){
            return Result.ok();
        }else{
            return Result.error("id不存在");
        }
    }
}
